package run.core;

import java.util.ArrayList;
import java.util.List;

import run.Cell;
import run.Facet;

/*
Negates booleans (represented as 1 or 0 
*/

public class NEGATE extends Cell {
	private Facet in, out;
	private ArrayList<Object> internalValue;
	
	public NEGATE(String labelName) {
		super("NEGATE", labelName);
		in = new Facet(".in", this, INPUT_FACET);
		out = new Facet(".out", this, OUTPUT_FACET);
		out.addSource(in);
	}
	
	@Override
	public List<Facet> stimulate(Facet stimmer) {
		ArrayList<Facet> doneFacets = new ArrayList<Facet>();
		
		List<Object> arg = in.dispatchOutbound();
		List<Object> vals = new ArrayList<Object>();
		
		// IGNORE NILS
		Object argo = arg.get(0);
		if (argo instanceof NIL) {
//			System.out.println("   NEGATE : nil");
			vals.add(argo);
			out.receive(in, vals);
			doneFacets.add(out);
			return doneFacets;
		}
		else {
			Integer i = (Integer) arg.get(0);
			
			if (i.intValue() == 0) {
				vals.add(new Integer(1));
				out.receive(in, vals);
			}
			else if (i.intValue() == 1) {
				vals.add(new Integer(0));
				out.receive(in, vals);
			}
			
			doneFacets.add(out);
			return doneFacets;
		}
	}
	
	public List<Facet> getFacets()
	{
		ArrayList<Facet> temp = new ArrayList<Facet>();
		temp.add(in);
		temp.add(out);
		return temp;
	}

	//Dot printout method
	public String toDot(String prefix)
	{
		String returnString = "";
		returnString += "subgraph " + "cluster_" + cellTypeName + hashCode() + "{\n";
		returnString += "label = \"" + cellTypeName + "\";\n";
		
		//Print my facets
		returnString +=  prefix + cellTypeName + hashCode() + "in [label=\"in\"];\n";
		returnString += prefix + cellTypeName + hashCode() + "out [label=\"out\"];\n";
		
		returnString += "}\n";
		return returnString;
	}
	
}
